﻿using Example.Application.Contracts;
using Example.Application.Dtos;
using Example.Domain.Contracts;
using Example.Domain.Entities;
using Sean.Utility.Contracts;
using Sean.Utility.Format;

namespace Example.Application.Services;

public class TestService : ITestService
{
    private readonly ILogger _logger;
    private readonly ITestRepository _testRepository;

    public TestService(
        ILogger<TestService> logger,
        ITestRepository testRepository
    )
    {
        _logger = logger;
        _testRepository = testRepository;
    }

    public bool Add(TestDto dto)
    {
        var testEntity = ObjectConvert.MapProperties<TestEntity>(dto);
        return _testRepository.Add(testEntity);
    }

    public bool DeleteById(long id)
    {
        return _testRepository.Delete(entity => entity.Id == id) > 0;
    }

    public TestDto GetById(long id)
    {
        var testEntity = _testRepository.Get(entity => entity.Id == id);
        return ObjectConvert.MapProperties<TestDto>(testEntity);
    }

    public void Hello(string name)
    {
        _logger.LogInfo($"你好！{name}");
    }
}